@extends('layouts.userctl')
@section('content')
<style>
	.layui-card-header {
		margin-top: 15px;
	}


	.userstatus {
		margin-left: 6px;
		color: #888;
		font-size: 14px;
	}

	.layui-table-tips-c::before {
		position: absolute !important;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0px !important;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.layui-table-cell{
		height: auto !important;
	}
</style>
{{csrf_field()}}
<div class="layuimini-container">
	<div class="layuimini-main">
		<div style="margin: 10px 10px 10px 10px" id="btn">
			<form class="layui-form layui-form-pane" action="">
				<div class="layui-form-item">
					<div class="layui-inline" style="float: right;">
						<!--注意此处button标签里的type属性-->
						<button type="button" class="layui-btn layui-btn-normal" lay-submit id="searchbtn"
							lay-filter="data-search-btn"><i class="layui-icon layui-icon-search"></i>搜 索</button>
					</div>
					<div class="layui-inline" style="float: right;">
						<label class="layui-form-label">关键字</label>
						<div class="layui-input-inline">
							<!--注意此处input标签里的id-->
							<input class="layui-input" name="keyword" id="keywordinput">
						</div>
					</div>
					<!-- <div class="layui-inline" style="float: left;">
						<a class="layui-btn layui-btn-normal" href="{{route('admin.user.adduser')}}"
							style="color: #fff;"><i class="layui-icon layui-icon-addition"></i>新增个人用户</a>
						<a class="layui-btn layui-btn-normal" href="{{route('admin.user.addcomuser')}}"
							style="color: #fff;"><i class="layui-icon layui-icon-addition"></i>新增企业用户</a>
						<a class="layui-btn layui-btn-normal" href="{{route('admin.user.adduser')}}"
							style="color: #fff;"><i class="layui-icon layui-icon-addition"></i>新增政府用户</a>
					</div> -->
				</div>
			</form>
		</div>
		<!--注意此处table标签里的id-->
		<table class="layui-table layui-hide" id="dataTable" lay-filter="dataTable"></table>
	</div>
</div>

<!-- <div class="layui-card">
	<div class="layui-card-header layuiadmin-card-header-auto">
		<a class="layui-btn layui-btn-normal" href="{{route('admin.user.adduser')}}" style="color: #fff;">新增用户</a>
	</div>
	<div class="layui-card-body">
		<table id="dataTable" lay-filter="dataTable"></table>
	</div>
</div> -->

<script>
	layui.use(['layer', 'table', 'form'], function() {
		var layer = layui.layer
	var form = layui.form
	var table = layui.table
	//用户表格初始化
	var dataTable = table.render({
			elem: '#dataTable',
			height: 'full',
			limit: 10,
			url: '{{ route("admin.com.data") }}',
			page: true,
			cols: [
				[ //表头
					{ field: 'comName', title: '名  称',width:150},
					{ field: 'province', title: '省  份' ,width:150,templet: function(d){
							if(d.place_1){
								return d.place_1.name
							}else{
								return ''
							}
							
						}},
					{ field: 'city', title: '城  市' ,width:150,templet: function(d){
							if(d.place_2){
								return d.place_2.name
							}else{
								return ''
							}
							
						}},
					{ field: 'district', title: '区' ,width:150,templet: function(d){
							if(d.place_3){
								return d.place_3.name
							}else{
								return ''
							}
							
						}},
					{ field: 'street', title: '街 道' ,width:150,templet: function(d){
							if(d.place_4){
								return d.place_4.name
							}else{
								return ''
							}
							
						}},
					{ field: 'community', title: '社  区' ,width:150,templet: function(d){
							if(d.place_5){
								return d.place_5.name
							}else{
								return ''
							}
							
						}},
					{ field: 'address', title: '街道门牌号' ,width:150},
					{ field: 'postcode', title: '邮政编码' ,width:150},
					{ field: 'leader', title: '法定代表人姓名' ,width:150},
					{ field: 'leaderPhone', title: '法定代表人电话' ,width:150},
					{ field: 'accompany', title: '企业陪同人员' ,width:150},
					{ field: 'workersNum', title: '员工人数' ,width:150},
					{ field: 'space', title: '占地面积' ,width:150},
					{ title: '主要负责人员姓名' ,width:150,templet: function(d){
							if(d.commanager.length>0){
								return d.commanager[0].name
							}else{
								return ''
							}
							
						},
					},
					{ title: '主要负责人员电话' ,width:150,templet: function(d){
							if(d.commanager.length>0){
								return d.commanager[0].phone
							}else{
								return ''
							}
							
						},},
					{ title: '主要负责人员微信' ,width:150,templet: function(d){
							if(d.commanager.length>0){
								return d.commanager[0].wx
							}else{
								return ''
							}
							
						},},
					{ title: '安全管理人员姓名' ,width:150,templet: function(d){
							if(d.safe_officer.length>0){
								return d.safe_officer[0].name
							}else{
								return ''
							}
						},},
					{ title: '安全管理人员电话' ,width:150,templet: function(d){
							if(d.safe_officer.length>0){
								return d.safe_officer[0].phone
							}else{
								return ''
							}
						},},
					{ field: 'yhqgpfifteen', title: '液化气钢瓶15KG' ,width:150},
					{ field: 'yhqgpfifty', title: '液化气钢瓶50KG' ,width:150},
					{ field: 'trqgd', title: '天然气管道' ,width:150,templet: function(d){
							if(d.trqgd==1){
								return '是'
							}else{
								return '否'
							}
						}},
					{ field: 'cjrl', title: '醇基燃料' ,width:150,templet: function(d){
							if(d.cjrl==1){
								return '是'
							}else{
								return '否'
							}
						}},
					{ field: 'photo', title: '门头照片' ,width:130,templet: function(d){
								if(d.photo && d.photo.length>5){
									return '<img src="'+d.photo+'" style="width:100px;height:100px;" class="smimg"/>'
								}else{
									return ''
								}
							},
					},
					{ field: 'license', title: '营业执照' ,width:130,templet: function(d){
								if(d.license && d.license.length>5){
									return '<img src="'+d.license+'" style="width:100px;height:100px;" class="smimg"/>'
								}else{
									return ''
								}
							},
					},
					{ field: 'service', title: '技术服务机构人员' ,width:150},
					{ field: 'area', title: '建筑面积' ,width:150},
					{ field: 'lat', title: '公司位置纬度' ,width:150},
					{ field: 'lng', title: '公司位置经度' ,width:150},
					
					{
						title: '操  作',fixed:"right",width:150,
						templet: function(d) {
							return '<a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="record">学 习</a>'
					}
					}
				]
			],
			done: function(response) { //定位当前table视图
				//动态监听表头高度变化，冻结行跟着改变高度
				$('.layui-table-header  tr').resize(function() {
					$('.layui-table-header  tr').each(function(index, val) {
						$($('.layui-table-fixed .layui-table-header table tr')[index])
							.height($(val).height())
				})
			})
			//初始化高度，使得冻结行表头高度一致
			$('.layui-table-header  tr').each(function(index, val) {
					$($('.layui-table-fixed .layui-table-header table tr')[index]).height($(
						val).height())
			})

			//表体部分
			//动态监听表体高度变化，冻结行跟着改变高度
			$('.layui-table-body  tr').resize(function() {
					$('.layui-table-body  tr').each(function(index, val) {
						$($('.layui-table-fixed .layui-table-body table tr')[index])
							.height($(val).height())
				})
			})
			//初始化高度，使得冻结行表体高度一致
			$('.layui-table-body  tr').each(function(index, val){
					$($('.layui-table-fixed .layui-table-body table tr')[index]).height($(val)
						.height())
			})
			var tableView = this.elem.next()

			//response.data获取后端返  回的JSON格式数据
			$.each(response.data, function(index, item) {

					//逻辑判断
					if (item.is_delete == '0') {
						//改变TR标签内字体颜色
						tableView.find('tbody tr[data-index="' + index + '"]').css('color',
							'#FF0033')
				}
				})
			}
		})
	$('#searchbtn').click(function() {
			dataTable.reload({
				where: { keyword: $('#keywordinput').val() },
				page: { curr: 1 }
			})
	})
	$(document).on('click','.smimg',function() {
		var url = $(this).attr('src')
		var img = '<img src=\'' + url +
			'\' style=\'width:800px;height:auto;max-height:800px;background-color:#fff;\'/>'
		layer.open({
			type: 1,
			title: false,
			scrollbar: false,
			area: ['800px', 'auto'],
			skin: 'layui-layer-nobg', //没有背景色
			shadeClose: true,
			content: img
		})
	})
	//监听工具条
		table.on('tool(dataTable)', function (obj) { //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
			var data = obj.data //获得当前行数据
					,
					layEvent = obj.event //获得 lay-event 对应的值
			if (layEvent === 'edit') {
				location.href = '/admin/com/comedit?id=' + data.id
			} else if (layEvent === 'selfentry') {
				location.href = '/admin/company/selfentrylist?id=' + data.id
			} else if (layEvent === 'record') {
				location.href = '/admin/selfWatchRecords/reportlist?id=' + data.id
			}
		})
})
</script>
@endsection
